#ifndef PROTOCOL_H_
#define PROTOCOL_H_

#include <stdint.h>
#include <stdio.h>
#include <string.h>

#define SP                          '?'
#define SPACE_LENGTH                 2
#define TYPE_ID_LENGTH              (sizeof(uint8_t))
#define INNER_TYPE_LENGTH(a)        (TYPE_ID_LENGTH + sizeof(a) + SPACE_LENGTH)
#define INNER_TYPE_WRAPPER_LENGTH   (SPACE_LENGTH+TYPE_ID_LENGTH)

#if defined(RC_DEBUG)
    #define RC_PRINT(fmt , ...) \
    do{ \
        printf(fmt , __VA_ARGS__); \
    }while(0)

    #define RC_LOG(fmt , ...)  \
    do{ \
        char* ptr = NULL; \
        { \
            if( (ptr = (char*)strrchr(__FILE__ , '\\')) != NULL)ptr++; \
            else if((ptr = (char*)strrchr(__FILE__ , '/')) != NULL)ptr++; \
            else ptr = __FILE__; \
        } \
        RC_PRINT(fmt , __VA_ARGS__); \
        RC_PRINT("\n\n------------------------log now-------------------------\n"); \
        RC_PRINT("FileName:  %s\n" , ptr); \
        RC_PRINT("Line    :  %d\n" , __LINE__); \
        RC_PRINT("Function:  %s"   , __FUNCTION__); \
        RC_PRINT("\n------------------------log end-------------------------\n\n"); \
    }while(0)
#else
    #define  RC_PRINT(fmt , ...)  
    #define  RC_LOG(fmt , ...)  
#endif


#define DISABLE_COPY_ASSIGN(classname) \
    private: \
        classname(const classname&); \
        const classname& operator=(const classname&)

namespace Remote
{
    typedef enum
    {
        ID_UINT8 = 0
        //ID_UINT8  = 0 , 
        //ID_UINT16 = 1 ,
        //ID_UINT32 = 2
    } TYPE_ID;


    enum
    {
        RET_SUCCESS   , 
        ERR_NULL_PTR = -1200, 
        ERR_WRONG_PARAM  ,
        ERR_NO_MEMORY    ,
        ERR_SYS_ERR      ,
        ERR_TIMEOUT      ,
        ERR_LISTEN_FAIL  ,
        ERR_SERVICE_NO_INIT  , 
        ERR_SERVICE_HAS_INIT , 
        ERR_SERVICE_INIT_FAILED ,
        ERR_NO_SERVICE   ,
        ERR_MAX_TRY_COUNT,
        ERR_BAD_PROTOCOL
    };

    template<class T> int inner_type_len()
    {
        return sizeof(T);
    }

    class IProtocol
    {
    public:
        virtual int32_t write_uint8(uint8_t data) = 0;
        virtual int32_t read_uint8(uint8_t& data) = 0;
    };
}
#endif //PROTOCOL_H_
